package com.escom.utils;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.escom.R;
import com.escom.healthlc.entidad.OximetroORM;

import java.util.List;

/**
 * Created by Carlos on 20/04/2014.
 */
public class CustomOximetroAdapter extends ArrayAdapter<OximetroORM> {

    private Context context;
    private List<OximetroORM> drawerItemOximetro;
    private int resource;

    public CustomOximetroAdapter(Context context, int resource, List<OximetroORM> drawerItemOximetro) {
        super(context, resource, drawerItemOximetro);
        this.context = context;
        this.drawerItemOximetro = drawerItemOximetro;
        this.resource = resource;
    }

    private static class PacienteViewHolder {
        TextView tVOximetroOxygenSaturation, tVOximetroBPM, tVOximetroDate;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PacienteViewHolder pacienteViewHolder;
        View view = convertView;

        if (view == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            view = inflater.inflate(resource, parent, false);
            pacienteViewHolder = new PacienteViewHolder();
            pacienteViewHolder.tVOximetroOxygenSaturation = (TextView) view.findViewById(R.id.tVOximetroOxygenSaturation);
            pacienteViewHolder.tVOximetroBPM = (TextView) view.findViewById(R.id.tVOximetroBPM);
            pacienteViewHolder.tVOximetroDate = (TextView) view.findViewById(R.id.tVOximetroDate);
            view.setTag(pacienteViewHolder);
        } else {
            pacienteViewHolder = (PacienteViewHolder) view.getTag();
        }

        OximetroORM oximetro = drawerItemOximetro.get((drawerItemOximetro.size() - 1) - position);
        Log.d(Constantes.LOG_ID, "Valor: " + oximetro.getBpm() + " Valor: " + oximetro.getOxygenSaturation());
        pacienteViewHolder.tVOximetroDate.setText(oximetro.getCreateDate());
        pacienteViewHolder.tVOximetroOxygenSaturation.setText(oximetro.getOxygenSaturation());
        pacienteViewHolder.tVOximetroBPM.setText(oximetro.getBpm());

        return view;
    }

    public void setDrawerItemOximetro(List<OximetroORM> drawerItemOximetro) {
        this.drawerItemOximetro = drawerItemOximetro;
    }
}
